//
//  UIView+Animations.m
//  FirstMatchThree
//
//  Created by Petar on 5/16/15.
//  Copyright (c) 2015 Nestorov Engineering. All rights reserved.
//

#import "UIView+Animations.h"
#import "Globals.h"

@implementation UIView (Animations)


- (void)startWobbleAnimationAfterDuration:(CGFloat)duration
{
    
    if ( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0") ) {
        
        self.transform = CGAffineTransformMakeScale(0.01f, 0.01f);
        
    } else {
        
        // start animation without delay for iOS 7
        duration = 0;
        
    }
    
    [self performSelector:@selector(startWobbleAnimation) withObject:nil afterDelay:duration];
    
}


- (void)startWobbleAnimation
{
    
    __weak UIView *weakSelf = self;
    
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction animations:^{
        
        weakSelf.transform = CGAffineTransformMakeScale(1,1);
        
    } completion:nil];
    
    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction animations:^{
        
        weakSelf.transform = CGAffineTransformMakeScale(1.1,0.95);
        
    } completion:nil];
    
}


- (void)stopAllAnimations
{
    
    [self.layer removeAllAnimations];
    
}

@end
